const app = getApp()
var page = 1;
var pagesize = 12;
var rid;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    shareImg: '/images/icon/code.png',
    bagImg: [
      '/images/icon/share1.png',
      '/images/icon/share2.png',
      '/images/icon/share3.png',
      '/images/icon/share4.png',
      '/images/icon/share5.png',
    ],
    hitenTop: false,
    chooseShare: false,
    animationData: {},
    userBasic: {},
    redPackAtil: {},
    redPackList: [],
  },

  baseImage: function() {
    var that = this;
    var data = that.data.bagImg;
    console.log('转码', data)
    for (var i = 0; i < data.length; i++) {
      var bgm = app.baseImage(data[i]);
      data[i] = bgm;
    }
    that.setData({
      bagImg: data
    })
  },
  chooseShare: function(e) {
    // 用that取代this，防止不必要的情况发生
    var that = this;
    // 创建一个动画实例
    var animation = wx.createAnimation({
      // 动画持续时间
      duration: 500,
      // 定义动画效果，当前是匀速
      timingFunction: 'linear'
    })
    // 将该变量赋值给当前动画
    that.animation = animation
    // 先在y轴偏移，然后用step()完成一个动画
    animation.translateY(200).step()
    // 用setData改变当前动画
    that.setData({
      // 通过export()方法导出数据
      animationData: animation.export(),
      // 改变view里面的Wx：if
      chooseShare: true
    })
    // 设置setTimeout来改变y轴偏移量，实现有感觉的滑动
    setTimeout(function() {
      animation.translateY(0).step()
      that.setData({
        animationData: animation.export()
      })
    }, 200)
  },
  hideModal: function(e) {
    var that = this;
    var animation = wx.createAnimation({
      duration: 1000,
      timingFunction: 'linear'
    })
    that.animation = animation
    animation.translateY(200).step()
    that.setData({
      animationData: animation.export()

    })
    setTimeout(function() {
      animation.translateY(0).step()
      that.setData({
        animationData: animation.export(),
        chooseShare: false
      })
    }, 200)
  },
  goUserInfo(){
    wx.switchTab({
      url: '../userInfo/index',
    })
  },
  goAddRedPag: function() {
    wx.switchTab({
      url: '../addRedpag/index',
    })
  },
  goCashRedPag: function() {
    wx.switchTab({
      url: '../cashRedpag/index',
    })
  },
  goShareOne:function(){
    wx.navigateTo({
      url: '../shareOne/index?rid='+rid,
    })
  },
  onShare: function() {
    this.chooseShare();
  },
  //获取个人基本信息
  getUserBasicInfo: function () {
    var that = this;
    var data = [];
    var url = 'We_Community/getBrowsePersonalUserBasic'
    var calkdata = app.netWorkRequest(that, data, url, 'userBasic')
  },
  //提取当条红包记录
  getOneRedenvelopeReceive: function() {
    var that = this;
    var data = [];
    data['rid'] = rid;
    var url = 'We_Redenvelopes/getOneRedenvelopeLet';
    var calkdata = app.netWorkRequest(that, data, url, 'redPackAtil')
  },
  //提取收红包记录
  getRedenvelopeReceiveList: function() {
    var that = this;
    var data = [];
    page = 1;
    data['rid'] = rid;
    data['page'] = page;
    data['pagesize'] = pagesize;
    var url = 'We_Redenvelopes/getRedenvelopeCodePassiveList';
    var calkdata = app.netWorkRequest(that, data, url, 'redPackList')
  },

  //加载更多收红包记录
  getRedenvelopeReceiveListLoadMore: function() {
    // 页数+1
    page = page + 1;
    console.log('椰树', page)
    var that = this;
    var data = [];
    data['rid'] = rid;
    data['page'] = page;
    data['pagesize'] = pagesize;
    var url = 'We_Redenvelopes/getRedenvelopeCodePassiveList';
    var f_data = that.data.redPackList;
    var calkdata = app.netWorkRequestLoadMore(that, data, url, 'redPackList', f_data);
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    rid = options.rid;
    this.baseImage();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {
    console.log('触发页面加载完成')
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    console.log('触发页面显示')
    this.getUserBasicInfo();
    this.getOneRedenvelopeReceive();
    this.getRedenvelopeReceiveList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {
    console.log('监听页面隐藏')
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {
    console.log('监听页面卸载')
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    this.getOneRedenvelopeReceive();
    this.getRedenvelopeReceiveList();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {
    wx.showLoading({
      title: '玩命加载中',
    })
    this.getRedenvelopeReceiveListLoadMore();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function(res) {
    var that = this;
    var t = that.data;
    var uid = t.redPackAtil['User_id'];
    wx.showShareMenu({
      withShareTicket: true
    })
    that.hideModal();
    that.setData({
      hitenTop: true
    })
    setTimeout(function() {
      that.setData({
        hitenTop: false
      })
    }, 3000)
    var title = '超级人脉给你发来了一个红包';
    var path = 'pages/visitorInfo/index?id=' + uid + '&sid=' + uid + '&rid=' + rid;
    var imageUrl ='';
    console.log('分享信息', path)
    return {
      title: title,
      path: path,
      // imageUrl: imageUrl,
    }
  }
})